<!-- company表单弹窗 -->
<form id="company-form" lay-filter="company-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">公司名字</label>
        <div class="layui-input-block">
            <input name="companyname" placeholder="请输入名字" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input name="people" placeholder="请输入HR" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input name="phone" placeholder="请输入手机号" type="text" class="layui-input" lay-verify="required|phone"
                   required/>
        </div>
    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input name="address" placeholder="请输入地址" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">简介</label>
                    <div class="layui-input-block">
                        <input name="information" placeholder="请输入公司简介" type="text" class="layui-input" lay-verify="required"
                               required/>
                    </div>
                </div>



<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">合作</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="radio" name="enabled" value="true" title="冻结" checked/>-->
<!--            <input type="radio" name="enabled" value="false" title="合作"/>-->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">角色</label>-->
<!--        <div class="layui-input-block">-->
<!--            <select name="roleId" xm-select="roleId" lay-verify="required">-->
<!--            </select>-->
<!--        </div>-->
<!--    </div>-->
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="company-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        form.render('radio');

        // 获取所有角色
        // layer.load(2);
        // admin.req('api-user/roles', {}, function (data) {
        //     layer.closeAll('loading');
        //     if (0 == data.code) {
        //         // 渲染多选下拉框
        //         var roleSelectData = new Array();
        //         for (var i = 0; i < data.data.length; i++) {
        //             roleSelectData.push({name: data.data[i].name, value: data.data[i].id});
        //         }
        //         formSelects.data('roleId', 'local', {arr: roleSelectData});

                // 回显user数据
                var company = admin.getTempData('t_company');

                $('#company-form').attr('method', 'POST');
                // if (company) {
                    form.val('company-form', company);
                //     $('#company-form').attr('method', 'POST');}
                    // var rds = new Array();
                //     for (var i = 0; i < company.roles.length; i++) {
                //         rds.push(company.roles[i].id);
                //     }
                //     formSelects.value('roleId', rds);
                // }

        //     } else {
        //         layer.msg('获取角色失败', {icon: 2, time: 500});
        //     }
        // }, 'GET');

        // 表单提交事件
        form.on('submit(company-form-submit)', function (data) {
            console.log(data,11111);
            layer.load(2);
            // admin.ajax({
            //     url: config.base_server + 'api-company/company/save',
            //     data: data,
            //     type: 'post',
            //     dataType: 'json',
            //     contentType: "application/json",
            //     success: success,
            //     beforeSend: function (xhr) {
            //         var token = config.getToken();
            //         if (token) {
            //             xhr.setRequestHeader('Authorization', 'Bearer ' + token.access_token);
            //         }
            //     }
            //
            // });
            admin.req('api-company/company/save', JSON.stringify(data.field), function (data) {
                console.log(data,3333);
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, $('#company-form').attr('method'));

            return false;
        });
    });
</script>